package tech.yangzhijie.basic.java04;

public class Java0502 {
    public static void main(String[] args) {

        //到原点的距离
        Point point1 = new Point(3, 4);
        double distance1 = Point.distanceToTheOrigin(point1);
        System.out.println("到原点的距离为："+distance1);//5
        //两点之间的距离
        Point point2 = new Point(3,4);
        Point point3 = new Point(6,4);
        double distance2 = Point.distanceBetweenTwoPoints(point2, point3);
        System.out.printf("%s,%s 这两点之间的距离为 %s\n",point2,point3,distance2);//3
        //三点是否构成三角形

        Point point4 = new Point(1,1);
        Point point5 = new Point(2,2);
        Point point6 = new Point(3,3);
        Point point7 = new Point(2,5);
        System.out.println(Point.whetherItConstitutesATriangle(point4, point5, point6));//false
        System.out.println(Point.whetherItConstitutesATriangle(point4, point5, point7));//true
    }
}

class Point{
    private int x;
    private int y;

    public Point() {
        this(0,0);
    }

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
    public void moveTo(int x,int y){
        this.x = x;
        this.y = y;
    }

    public static double distanceToTheOrigin(Point p){
        return distanceBetweenTwoPoints(p,new Point());
    }

    public static double distanceBetweenTwoPoints(Point p1,Point p2){
        return Math.sqrt(Math.pow(p1.x - p2.x,2)+Math.pow(p1.y - p2.y,2));
    }

    public static String whetherItConstitutesATriangle(Point p1,Point p2,Point p3){
        double distance1 = distanceBetweenTwoPoints(p1, p2);
        double distance2 = distanceBetweenTwoPoints(p1, p3);
        double distance3 = distanceBetweenTwoPoints(p2, p3);
        if((distance1 + distance2) > distance3 && (distance1 + distance3) > distance2 && (distance2 + distance3) > distance1){
            return String.format("%s,%s,%s 这三点可以构成三角形",p1,p2,p3);
        }
        return String.format("%s,%s,%s 这三点不可以构成三角形",p1,p2,p3);
    }

    @Override
    public String toString() {
        return String.format("(%s,%s)",x,y);
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
}